package net.betou.trade.entity.main;

import java.util.Date;

import org.apache.commons.lang.StringUtils;

import net.betou.common.util.DataConvertUtils;
import net.betou.trade.entity.main.base.BaseChannel;

/**
 * 栏目实体类
 * 
 * @author 叶装装
 * 
 */
public class Channel extends BaseChannel {
	private static final long serialVersionUID = 1L;

	public Channel( ) {
	}
	
	public void init( Channel current ){
		
		if( current != null ){
			this.setDeep( current.getDeep( ) + 1 );
			this.setParent( current );
		}else{
			this.setDeep( 0 );
		}
		this.setAddDate( new Date( ) );
		
		blankToNull( );
	}
	
	public void blankToNull( ){
		if( getPriority( ) == null ){
			setPriority( 10 );
		}
	}
	
	public Integer [ ] getMxGroups( ){
		String [ ] splitId = StringUtils.split( this.getOrientedGroup( ), "," );
		Integer [ ] ids = new Integer[ splitId.length ];
		
		for( int i = 0; i < splitId.length; i++ ){
			ids[ i ] = DataConvertUtils.getInt( splitId[ i ] );
		}
		
		return ids;
		
	}
	
	public Integer [ ] getSmsGroups( ){
		if( this.getSmsGroup( ) == null ){
			return null;
		}
		String [ ] splitId = StringUtils.split( this.getSmsGroup( ), "," );
		Integer [ ] ids = new Integer[ splitId.length ];
		
		for( int i = 0; i < splitId.length; i++ ){
			ids[ i ] = DataConvertUtils.getInt( splitId[ i ] );
		}
		
		return ids;
	}

}